﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Money.Plugins
{
    // TODO at the minute we create one of each type within the plugin and then dont use it, we should refactor this to store the type
    // TODO we may need to keep the initial instance as we use things like graph name from it
    public class Graphs
    {
        public IGraph GetGraph(string Name)
        {
            IGraph requestedGraph = null;

            foreach (IGraph graph in PluginHost.GraphPlugins)
            {
                if (graph.Name.Equals(Name))
                {
                    // create a new instance of the required graph type
                    requestedGraph = (IGraph)Activator.CreateInstance(graph.GetType());
                    break;
                }
            }

            return requestedGraph;
        }

        public IEnumerable<IGraph> GetGraphs()
        {
            return PluginHost.GraphPlugins;
        }

        public IEnumerable<string> GetGraphNames()
        {
            foreach (IGraph graph in PluginHost.GraphPlugins)
            {
                yield return graph.Name;
            }
        }
    }
}
